package com.habbot.beautifyinghandbook.models;

import java.util.ArrayList;
import java.util.List;

import com.habbot.beautifyinghandbook.daos.DBAdapter;
import com.habbot.beautifyinghandbook.objects.MenuObject;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class MenuTable {
	public static final String TB_NAME = "ZMENU";
	public static final String COL_ID = "Z_PK", COL_NAME = "ZNAME",
			COL_ENT = "Z_ENT", COL_OPT = "Z_OPT";

	private DBAdapter dbAdapter;

	public MenuTable(Context context) {
		dbAdapter = DBAdapter.getInstance(context);
	}

	public List<MenuObject> getAllMenu() {
		List<MenuObject> menu = new ArrayList<MenuObject>();
		try {
			SQLiteDatabase database = dbAdapter.openDataBase();
			Cursor cusor = database.rawQuery("select * from " + TB_NAME
					+ " ORDER BY " + COL_ID + " ASC", null);
			while (cusor.moveToNext()) {
				MenuObject menuItem = new MenuObject();
				menuItem.setId(cusor.getInt(cusor.getColumnIndex(COL_ID)));
				menuItem.setTitle(cusor.getString(cusor
						.getColumnIndex(COL_NAME)));
				menuItem.setEnt(cusor.getInt(cusor.getColumnIndex(COL_ENT)));
				menuItem.setOpt(cusor.getInt(cusor.getColumnIndex(COL_OPT)));
				menu.add(menuItem);
			}
			dbAdapter.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return menu;
	}

}
